﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Web.Profile;

namespace WebSite.admin
{
    public partial class language : System.Web.UI.Page
    {

        private static string DBConnectionString = (DBDriver + HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath + "/App_Data/") + DBName);
        public static readonly string DBDriver = ConfigurationManager.AppSettings.Get("DBDriver").ToString();
        public static readonly string DBName = ConfigurationManager.AppSettings.Get("DBName").ToString();
        protected ImageButton ImageButton1;

        // Methods
        private void Bind()
        {
            string sql = "select * from DB_Language";
            DataSet set = SQLAccess.GreatDs(sql);
            this.DataList1.DataSource = set;
            this.DataList1.DataBind();
            string str2 = "select * from DB_Language";
            DataSet set2 = SQLAccess.GreatDs(str2);
            this.DataList2.DataSource = set2;
            this.DataList2.DataBind();
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            string str = "";
            foreach (Control control in this.DataList1.Controls)
            {
                CheckBox box = (CheckBox)control.FindControl("CheckBox1");
                str = str + box.Text + "<br>";
                SQLAccess.DoSql(string.Concat(new object[] { "update DB_Language set visible=", box.Checked ? "1" : "0", " where languages='", box.Text, "'" }));
            }
            string str3 = "";
            foreach (Control control2 in this.DataList2.Controls)
            {
                RadioButton button = (RadioButton)control2.FindControl("rbttruck");
                str3 = str3 + button.Text + "<br>";
                string sql = string.Concat(new object[] { "update DB_Language set istrue=", button.Checked ? "1" : "0", " where languageid=", button.GroupName, "" });
                base.Response.Write("");
                SQLAccess.DoSql(sql);
            }
            base.Response.Write("<script language=javascript>alert('修改成功,请刷新前台首页！');window.location.href='language.aspx';</script>");
            base.Response.End();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["Adminlogin"] == null)
            {
                base.Response.Write("<script language=javascript>window.top.location.href='login.aspx';</script>");
            }
            else if (!base.IsPostBack)
            {
                this.Bind();
            }
        }

        public void SetFalseone(object sender, EventArgs e)
        {
            RadioButton button = (RadioButton)sender;
            DataListItem parent = (DataListItem)button.Parent;
            for (int i = 0; i < this.DataList2.Items.Count; i++)
            {
                if (i != parent.ItemIndex)
                {
                    RadioButton button2 = (RadioButton)this.DataList2.Items[i].FindControl("rbttruck");
                    button2.Checked = false;
                }
            }
        }



    }
}